﻿$(function addDatepicker() {
    if ($(".inner_input_date").length != 0) {
        $(".inner_input_date").datepicker({
            changeYear: true,
            changeMonth: true,
            onSelect: function (date) { },
            beforeShow: function (input, inst) {
                var offset = $(input).offset();
                window.setTimeout(function () {
                    var scrollTop = document.documentElement.childNodes[1].scrollTop;
                    var calWidth = inst.dpDiv.width();
                    var inpWidth = $(input).width() + parseInt($(input).css('padding'));
                    if ((offset.left + calWidth) > $(document.body).width()) {
                        inst.dpDiv.css({ top: (offset.top + $(input).height() + scrollTop + 4) + 'px', left: offset.left + (inpWidth - calWidth) + 'px' })
                    } else {
                        inst.dpDiv.css({ top: (offset.top + $(input).height() + scrollTop + 4) + 'px', left: offset.left + 'px' })
                    }
                }, 1);
            }
        });
    }
});

$(function addTimepicker() {
    if ($(".inner_input_time").length != 0) {
        $('.inner_input_time').datetimepicker({
            timeFormat: "HH:mm:ss",
            dateFormat: "yy-mm-dd",
            beforeShow: function (input, inst) {
                var offset = $(input).offset();
                window.setTimeout(function () {
                    var scrollTop = document.documentElement.childNodes[1].scrollTop;
                    var calWidth = inst.dpDiv.width();
                    var inpWidth = $(input).width() + parseInt($(input).css('padding'));
                    if ((offset.left + calWidth) > $(document.body).width()) {
                        inst.dpDiv.css({ top: (offset.top + $(input).height() + scrollTop - 430) + 'px', left: offset.left + (inpWidth - calWidth) + 'px' })
                    } else {
                        inst.dpDiv.css({ top: (offset.top + $(input).height() + scrollTop - 430) + 'px', left: offset.left + 'px' })
                    }
                }, 1);
            }
        });
    }
});

$(function addTimepickerOne() {
    if ($(".inner_input_time2").length != 0) {
        $('.inner_input_time2').datetimepicker({
            timeFormat: "HH:mm:ss",
            dateFormat: "yy-mm-dd",
            beforeShow: function (input, inst) {
                var offset = $(input).offset();
                window.setTimeout(function () {
                    var scrollTop = document.documentElement.childNodes[1].scrollTop;
                    var calWidth = inst.dpDiv.width();
                    var inpWidth = $(input).width() + parseInt($(input).css('padding'));
                    if ((offset.left + calWidth) > $(document.body).width()) {
                        inst.dpDiv.css({ top: (offset.top + $(input).height() + scrollTop + 6) + 'px', left: offset.left + (inpWidth - calWidth) + 'px' })
                    } else {
                        inst.dpDiv.css({ top: (offset.top + $(input).height() + scrollTop + 6) + 'px', left: offset.left + 'px' })
                    }
                }, 1);
            }
        });
    }
});

function addCheck() {
    if ($(".selectSub>input:checked").length == 0) {
        return true;
    }
    if ($(".selectSub>input:checked").length > 1) {
        alert("添加时只能选择一条记录！");
        return false;
    }
    return true;
}

function isSelectAndDelete() {
    var result = true;
    $(".selectSub>input").each(function () {
        if ($(this).attr("checked")) {
            result = false;
        }
    });
    if (result) {
        alert("没有选择任何记录！");
        return false;
    } else {
        if (window.confirm("您确认要删除吗？")) {
            return true;
        } else {
            return false;
        }
    }
}

function isSelectAndPrint() {
    var result = true;
    $(".selectSub>input").each(function () {
        if ($(this).attr("checked")) {
            result = false;
        }
    });
    if (result) {
        alert("没有选择任何记录！");
        return false;
    } else {
        if (checkLodop() == true) {
            if (window.confirm("您确认要打印条码吗？")) {
                return true;
            } else {
                return false;
            }
        } else {
            return false;
        }
    }
}

function showMessage(message) {
    $("#message").html("");
    var msg = "";
    var s = Object.prototype.toString.call(message);
    if (s == "[object String]") {
        msg = "<span>" + message + "</span>";
    }
    if (s == "[object Array]") {
        for (i = 0; i < message.length; i++) {
            msg = msg + "<span>" + message[i] + "</span><br>";
        }
    }
    $("#message").html(msg);
}

function clearMessage() {
    $(".message").html("");
}

function setCurPage() {
    $(".num_yellow").replaceWith("<span class='pageIndexs'>" + $(".num_yellow").html() + "</span>");
}

String.prototype.format = function (args) {
    if (arguments.length > 0) {
        var result = this;
        if (arguments.length == 1 && typeof (args) == "object") {
            for (var key in args) {
                var reg = new RegExp("({" + key + "})", "g");
                result = result.replace(reg, args[key]);
            }
        } else {
            for (var i = 0; i < arguments.length; i++) {
                if (arguments[i] == undefined) {
                    return "";
                } else {
                    var reg = new RegExp("({[" + i + "]})", "g");
                    result = result.replace(reg, arguments[i]);
                }
            }
        }
        return result;
    } else {
        return this;
    }
}

function getMessage(strId) {
    if ($("#" + strId) == null) {
        return "";
    }
    return $("#" + strId).val();
}

function setMessage(arrMsg) {
    var html;
    for (i = 0; i < arrMsg.length; i++) {
        html = html + "<input type='hidden' id='" + arrMsg[i].id + "' value='" + arrMsg[i].msg + "' />"
    }
    $("#jsMessage").html(html);
}

function showMessage(arrMsg) {
    var msg = "";
    for (i = 0; i < arrMsg.length; i++) {
        msg = msg + arrMsg[i] + '\n';
    }
    alert(msg);
}

function showAttachDownload(bisAttachId) {

    window.showModalDialog("../Common/attachDownload.aspx?bisAttachId=" + bisAttachId, "", "dialogWidth=400px;dialogHeight=400px");
}

function changeCheckBox() {
    var chk = $(".chkAll").attr("checked");
    if (chk) {
        $(".selectSub>input").attr("checked", true);
    } else {
        $(".selectSub>input").attr("checked", false);
    }
}

function changeCheckBoxUser() {
    var chk = $(".chkAll").attr("checked");
    if (chk) {
        $(".selectSub").attr("checked", true);
    } else {
        $(".selectSub").attr("checked", false);
    }
}

window.onload = function () {
    $(".selectSub>input").click(function () {
        var isCheckAll = true;
        $(".selectSub>input").each(function () {
            if (!this.checked) {
                isCheckAll = false;
            }
        });
        $(".chkAll").attr("checked", isCheckAll);
    });
    $(".chkAll").change(function () {
        var chk = $(".chkAll").attr("checked");
        if (chk) {
            $(".selectSub>input").attr("checked", true);
        } else {
            $(".selectSub>input").attr("checked", false);
        }
    });
    $(".selectSub2>input").click(function () {
        var isCheckAll = true;
        $(".selectSub2>input").each(function () {
            if (!this.checked) {
                isCheckAll = false;
            }
        });
        $(".chkAll2").attr("checked", isCheckAll);
    });
    $(".chkAll2").change(function () {
        var chk = $(".chkAll2").attr("checked");
        if (chk) {
            $(".selectSub2>input").attr("checked", true);
        } else {
            $(".selectSub2>input").attr("checked", false);
        }
    });
}
function zenToHan(value) {
    var result = "";
    for (i = 0; i < value.length; i++) {
        code = value.charCodeAt(i);
        if (code >= 65281 && code <= 65373) {
            result += String.fromCharCode(value.charCodeAt(i) - 65248);
        } else if (code == 12288) {
            result += String.fromCharCode(value.charCodeAt(i) - 12288 + 32);
        } else {
            result += value.charAt(i);
        }
    }
    return result;
}

//获取系统时间，将时间以指定格式显示到页面。  
function systemTime() {
    //获取系统时间
    var dateTime = new Date();

    var yy = dateTime.getFullYear(); //年份
    var MM = dateTime.getMonth() + 1;  //月份-因为1月这个方法返回为0，所以加1
    var dd = dateTime.getDate(); //日数

    var hh = dateTime.getHours();
    var mm = dateTime.getMinutes();
    var ss = dateTime.getSeconds();

    //分秒时间是一位数字，在数字前补0。  
    mm = extra(mm);
    ss = extra(ss);
    MM = extra(MM);
    dd = extra(dd);

    //将时间显示到ID为time的位置，时间格式形如：19:18:02
    var systemTime = yy + "/" + MM + "/" + dd + " " + hh + ":" + mm + ":" + ss;
    $("#ctl00_ContentPlaceHolder1_txtSystemTime").val(systemTime);

    //每隔1000ms执行方法systemTime()  
    setTimeout("systemTime()", 1000);
}

//补位函数。  
function extra(x) {
    //如果传入数字小于10，数字前补一位0。  
    if (x < 10) {
        return "0" + x;
    }
    else {
        return x;
    }
}

//补零
function pad(num, n) {
    var len = num.toString().length;
    while (len < n) {
        num = "0" + num;
        len++;
    }
    return num;
}

function getRowNum(obj) {
    var rowIndex, c
    o = obj
    while (o.tagName != "TD") {
        o = o.parentNode
    }
    if (o.tagName != "TD") {
        return
    }
    c = o.cellIndex
    while (o.tagName != "TR") {
        o = o.parentNode
    }
    if (o.tagName != "TR") {
        return
    }
    rowIndex = o.rowIndex
    return rowIndex;
}

var LODOP;

//打印试剂标签
function printLabel(printdiv) {
    if (checkLodop()) {
    	LODOP = getLodop();
    	LODOP.SET_PRINTER_INDEX("ZDesigner 110Xi4 600 dpi-Lab");
        LODOP.SET_PRINT_PAGESIZE(1, "110mm", "45mm", "");
        var	strBodyStyle = "<style>" + document.getElementById("printStyle").innerHTML + "</style>";
        
        var strFormHtml = strBodyStyle + "<body>" + document.getElementById(printdiv).innerHTML + "</body>";
		LODOP.ADD_PRINT_TABLE(10, 10, "45mm", "110mm", strFormHtml);
        LODOP.PRINT();
    }
}

function checkLodop() {
    LODOP = getLodop();
    if (LODOP == null) {
        return false;
    }
    return true;
}

//减法运算
function subtr(arg1, arg2) {
    var r1, r2, m, n;
    try { r1 = arg1.toString().split(".")[1].length } catch (e) { r1 = 0 }
    try { r2 = arg2.toString().split(".")[1].length } catch (e) { r2 = 0 }
    m = Math.pow(10, Math.max(r1, r2));
    //last modify by deeka
    //动态控制精度长度
    n = (r1 >= r2) ? r1 : r2;
    return ((arg1 * m - arg2 * m) / m).toFixed(n);
}

//加法函数，用来得到精确的加法结果
//说明：javascript的加法结果会有误差，在两个浮点数相加的时候会比较明显。这个函数返回较为精确的加法结果。
//调用：accAdd(arg1,arg2)
//返回值：arg1加上arg2的精确结果
function accAdd(arg1, arg2) {
    var r1, r2, m;
    try { r1 = arg1.toString().split(".")[1].length } catch (e) { r1 = 0 }
    try { r2 = arg2.toString().split(".")[1].length } catch (e) { r2 = 0 }
    m = Math.pow(10, Math.max(r1, r2))
    return accDiv((accMul(arg1, m) + accMul(arg2, m)), m)
}

//乘法函数，用来得到精确的乘法结果
//说明：javascript的乘法结果会有误差，在两个浮点数相乘的时候会比较明显。这个函数返回较为精确的乘法结果。
//调用：accMul(arg1,arg2)
//返回值：arg1乘以arg2的精确结果
function accMul(arg1, arg2) {
    var m = 0, s1 = arg1.toString(), s2 = arg2.toString();
    try { m += s1.split(".")[1].length } catch (e) { }
    try { m += s2.split(".")[1].length } catch (e) { }
    return Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m)
}

//除法函数，用来得到精确的除法结果
//说明：javascript的除法结果会有误差，在两个浮点数相除的时候会比较明显。这个函数返回较为精确的除法结果。
//调用：accDiv(arg1,arg2)
//返回值：arg1除以arg2的精确结果
function accDiv(arg1, arg2) {
    var t1 = 0, t2 = 0, r1, r2;
    try { t1 = arg1.toString().split(".")[1].length } catch (e) { }
    try { t2 = arg2.toString().split(".")[1].length } catch (e) { }
    with (Math) {
        r1 = Number(arg1.toString().replace(".", ""))
        r2 = Number(arg2.toString().replace(".", ""))
        return (r1 / r2) * pow(10, t2 - t1);
    }
}

/********************************************************************************
* 機　能 : 画面按钮按下时，“处理中”表示
* 引　数 : s_waitType .......... Wait Type
*          0:検索中…
*          1:CSV作成中…
*          2:PDF作成中…  
********************************************************************************/
function drawWait(s_waitType) {
    if (document.getElementById('divWait')) {

        var l_Top = Math.round(window.screen.height / 2 - 140);
        var l_Left = Math.round(window.screen.width / 2 - 150);
        var obj = document.getElementById('divWait');
        obj.style.top = 0;
        obj.style.left = 0;
        obj.style.width = "100%";
        obj.style.height = "100%";

        var html = '<table width="100%" height="100%"  style="Z-INDEX: 999; CURSOR: wait " border="0">'
        html += '<tr valign="middle"  align="center">';
        html += '<td>';
        html += '<FIELDSET style="WIDTH:273px;HEIGHT:66px;CURSOR: wait;" >';
        html += '<TABLE  id="Table1" style="font-size: 14px;color : white; background-color : #8080ff;border-color : #8080ff;font-weight : bold;WIDTH: 268px; HEIGHT: 35px; CURSOR: wait;" height="35" cellSpacing="3" cellPadding="3" width="268" border="0">';
        html += '<TR class="op_work_item" valign="middle" style="color : black; background-color : #DDDDFF;border-color : #8080ff;font-weight : bold;width: 100%;height: 30px; CURSOR: wait;"  align="center">';
        html += '<TD>';
        html += '<FIELDSET style=" CURSOR: wait;"  ><br>';

        switch (s_waitType) {
            case '0': //检索
                html += "/u68C0/u7D22/u5904/u7406/u4E2D/u2026<br>";
                html += "/u8BF7/u7A0D/u7B49";
                break;
            case '1': //登陆
                html += "/u767B/u9646/u5904/u7406/u4E2D/u2026<br>";
                html += "/u8BF7/u7A0D/u7B49";
                break;
            case '2': //删除
                html += "/u5220/u9664/u5904/u7406/u4E2D/u2026<br>";
                html += "/u8BF7/u7A0D/u7B49";
                break;
            case '3': //CSV
                html += "CSV/u5904/u7406/u4E2D/u2026<br>";
                html += "/u8BF7/u7A0D/u7B49";
                break;
        }

        html += '<br> &nbsp;';
        html += '</FIELDSET>';
        html += '</TD>';
        html += '</TR>';
        html += '</TABLE>';
        html += '</FIELDSET>';
        html += '</TD>';
        html += '</TR>';
        html += '</TABLE>';
        obj.innerHTML = html;

        if (s_waitType == '3' || s_waitType == '5') {
            window.setTimeout("closeWait();", 3000);
        }
    }
}


/**************************************************************** 
* 機　能： 等待画面关闭
* 引　数：  
****************************************************************/
function closeWait() {
    if (document.getElementById('divWait')) {

        var obj = document.getElementById('divWait');

        obj.style.top = 0;
        obj.style.left = 0;

        obj.style.width = "0";
        obj.style.height = "0";

        obj.innerHTML = '';
    }
}